package com.example.shardingjdbc.controller;

import com.example.shardingjdbc.dao.OrderDao;
import com.example.shardingjdbc.dao.OrderMapper;
import com.example.shardingjdbc.model.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: zhang.rongqing
 * @since: 2019/10/15
 */
@RestController
@RequestMapping(value = "/test")
public class TestController {

    @Autowired
    private OrderDao orderDao;

    @Autowired
    private OrderMapper orderMapper;

    @GetMapping
    public String hello(){
        return "hello Sharding-jdbc";
    }

    @PostMapping
    public void insert(@RequestParam Long orderId , @RequestParam Long userId){
        Order order = Order.builder().userId(userId).orderId(orderId).build();
        orderDao.create(order);
        System.out.println(String.format("create id : %s",order.getId()));
    }

    @PostMapping(value = "insert")
    public void insert2(@RequestParam Long orderId , @RequestParam Long userId){
        Order order = Order.builder().userId(userId).orderId(orderId).build();
        orderMapper.create(order);
        System.out.println(String.format("create id : %s",order.getId()));
    }
}
